if (!jsx3.lang.Class.forName("ux.cdb.admin.receiptPkg.ReceiptPkgProv")) {

/**
 * Define the <code>name of class</code> class.
 * This class inherit from <code>jsx3.gui.Block<code> GUI class.
 */
jsx3.Class.defineClass(
		"ux.cdb.admin.receiptPkg.ReceiptPkgProv",
		jsx3.gui.Block,
		null,
		function (objRoot) {

			objRoot.prototype.property = function(name, token) {
				return ux.megatron.Main.getServer().getDynamicProperty(name, token);
			};

			objRoot.prototype.onAfterDeserialize = function() {
				this.getPrivilege();
				this.isCountry = false;
				this.blkRcpDesc = this.get("blkRcpDesc");
				this.blkRcpDetail = this.get("blkRcpDetail");
				this.mtxRcpPkg = this.get("mtxRcpPkg");	
				this.batchApprovalInfoId = null;
				this.blkRcpDesc.show();
				
				this.curPage = ux.megatron.Main.getServer().getDynamicProperty("@cdb@package@curPage");
				this.pageSize = ux.megatron.Main.getServer().getDynamicProperty("@cdb@package@pageNum");
				this.pagebar = this.get("blkPageWheel");
                this.pagebar.initialize();
				this.pagebar.bindWithMatrix(this, this.loadPagination, this.mtxRcpPkg);

				var me = this;
				this.mtxRcpPkg.subscribe(ux.cdb.admin.gui.Matrix.EVENT_CHECKALL,me,me.onCheckBtnStatus);

				ux.megatron.util.Dwr.callDwr("RetailStudentLoanContractFeedBackCountryUCC", 
					"getInternalOrgInfo", null,
					me,me.callBackGetInternalOrgInfo, 
					"RetailStudentLoanContractFeedBackCountryUCC");	
			}

			objRoot.prototype.callBackGetInternalOrgInfo = function(dwrObjectList){
				if(!dwrObjectList)
					jsx3.log("call getInternalOrgInfo failed......");
				this.orgId = dwrObjectList.content.data[0].orgID;
				this.orgName = dwrObjectList.content.data[0].orgName;
				this.get("blkPartyName").getChildren()[1].setValue(this.orgName);
				this.loadFilterList();
				//not load data from server automatic
				//this.loadRcpPkgData();
			}

			objRoot.prototype.getPrivilege = function() {
				var  privilegebtnNew = ux.cdb.admin.Privilege.getPrivilege(30);
				var  privilegebtnPrint = ux.cdb.admin.Privilege.getPrivilege(31);
				var  privilegebtnReport = ux.cdb.admin.Privilege.getPrivilege(32);
				if(privilegebtnNew == null){
					this.get("btnNew").hide();
				}else{
					this.get("btnNew").show();
					this.get("btnNew").enable();
				}

				if(privilegebtnPrint == null){
					this.get("btnPrint").hide();
				}else{
					this.get("btnPrint").show();
					this.get("btnPrint").disable();
				}

				if(privilegebtnReport == null){
					this.get("btnReport").hide();
				}else{
					this.approvalRole = 1;
					this.get("btnReport").show();
					this.get("btnReport").disable();
				}
            }; 

			objRoot.prototype.loadPagination = function(msg) {
                this.curPage = (msg && msg.currentPageNumber) ? msg.currentPageNumber : (this.curPage || 1);
                this.loadRcpPkgData();
            };

			objRoot.prototype.loadFilterList = function(){
				ux.megatron.Main.loadResource("ux/cdb/admin/receiptPkg/docs/rcpStatusFilter.xml", 
						"ux.cdb.admin", "rcpPkgFilter_0303_1", "xml");
				this.get("selRcpStatusFilter").repaint();
			}

			objRoot.prototype.loadRcpPkgData = function(){
				var me = this;
				ux.megatron.util.Dwr.callDwr("UploadRetailStudentLoanContractFeedBackProvinceUCC", 
					"getBatchInfoList",  [this.batchApprovalInfoId,this.curPage,this.pageSize], 
					me,me.callBackGetBatchInfoList,
					"UploadRetailStudentLoanContractFeedBackProvinceUCC");
			}

			objRoot.prototype.callBackGetBatchInfoList = function(dwrObjectList){
				if(!dwrObjectList)
					jsx3.log("call rcpProvincePkgListCallBack failed......");

				this.totalRecordCount = dwrObjectList.content.page.count;
				this.totalPages = (this.totalRecordCount % this.pageSize > 0) ? (parseInt(this.totalRecordCount / this.pageSize) + 1) : (this.totalRecordCount / this.pageSize);
				if (this.totalPages == 0) this.totalPages = 1;
				this.pagebar.setValue(this.curPage,this.totalPages,this.pageSize,this.totalRecordCount); 

				var cdfDoc = ux.megatron.util.Dwr.toShallowCdf(dwrObjectList.content.data); 
				this.mtxRcpPkg.setSourceXML(cdfDoc);
				this.mtxRcpPkg.repaint();
			}

			objRoot.prototype.onRefreshUI = function(){
				this.blkRcpDesc.show();
				this.blkRcpDetail.hide();
				this.setBtn(["btnNew"],["btnPrint","btnReport"]);
				//this.get("selRcpStatusFilter").setValue(null);
				this.loadRcpPkgData();
			}

			objRoot.prototype.onNewPkg = function(){
				var parent = ux.megatron.Main.getServer().getBodyBlock();
				var me = this;
				ux.megatron.Main.loadUIResourceAsync(parent,
						"ux.cdb.admin",
						"ux/cdb/admin/receiptPkg/pkgWizard/ui/pkgBuilderDailog.xml",
						me, me.wizardLoaded);
			}

			objRoot.prototype.wizardLoaded = function(objEvent){ 
				this.wizardDlg = objEvent.obj;
				this.wizardDlg.opener = this;  
				this.wizardDlg.isCountry = this.isCountry;  
				this.wizardDlg.orgId = this.orgId;  
				this.wizardDlg.orgName = this.orgName;  
			}

			objRoot.prototype.onQueryClick = function(){
				this.batchApprovalInfoId = this.get("blkApprovalID").getChildren()[1].getValue();
				this.loadRcpPkgData();
			}

			objRoot.prototype.onPrintRcpPkg = function(){
				var AppBasicInfoID = this.mtxRcpPkg.getCheckedNodes().get(0).getAttribute("batchApprovalInfoId");
				this.get("iframeExport").setSrc("/dwr/RetailStudentLoanContractFeedBackProvinceServlet?AppBasicInfoID=" + AppBasicInfoID);
			}

/*			objRoot.prototype.onPrintRcpPkg = function(){
				var parent = ux.megatron.Main.getServer().getBodyBlock();
				var me = this;
				ux.megatron.Main.loadUIResourceAsync(parent,
						"ux.cdb.admin",
						"ux/cdb/admin/receiptPkg/ui/printDlg.xml",
						me, me.printDialogLoaded);
			}

			objRoot.prototype.printDialogLoaded = function(objEvent){ 
				this.printDialog = objEvent.obj;
				var AppBasicInfoID = this.mtxRcpPkg.getCheckedNodes().get(0).getAttribute("batchApprovalInfoId");
				this.printDialog.get("iframePrint").setSrc("/dwr/RetailStudentLoanContractFeedBackProvinceServlet?AppBasicInfoID=" + AppBasicInfoID);
			}
*/
			objRoot.prototype.onReportRcpPkg = function(){
				var me = this;
				var tipTitle = this.property("@cdb@package@reportRcpPkgTitle");
				var tipContent = this.property("@cdb@package@reportRcpPkgContent",this.mtxRcpPkg.getCheckedNodes().size());
				ux.megatron.Dialog.confirm(tipTitle, tipContent, function(dialog){
					var onReportPkg = me.mtxRcpPkg.getCheckedNodes();
					var idArray = new Array();
					for(var i=0 ;i<onReportPkg.size();i++){
						var recordObj = new Object();
						recordObj.batchApproveInfoId = onReportPkg.get(i).getAttribute("batchApprovalInfoId");
						recordObj.virtualApproveObjectId = onReportPkg.get(i).getAttribute("virtualApproveObjectId");
						idArray.push(recordObj);
					}
					ux.megatron.util.Dwr.callDwr("UploadRetailStudentLoanContractFeedBackProvinceUCC",
							"uploadProvinceBatchContractInfoList",
							[idArray],
							me,me.callBackReport,
							"UploadRetailStudentLoanContractFeedBackProvinceUCC");
					dialog.doClose();
				}, null);
			}

			objRoot.prototype.callBackReport = function(dwrObject){
				var tipTitle = this.property("@cdb@package@tipAlertTitle");
				var tipContent = null;
				var me = this;
				if(dwrObject.res.flag == 1){
					tipContent = this.property("@cdb@package@reportSuccess");
					ux.megatron.Dialog.alert(tipTitle,tipContent,function(dialog){
						me.get("selRcpStatusFilter").setValue(null);
						me.setBtn(["btnNew"],["btnPrint","btnReport"]);
						me.onRefreshUI();
						dialog.doClose();
					})

				}else{
					tipContent = this.property("@cdb@package@reportFailed");
					ux.megatron.Dialog.alert(tipTitle,tipContent,function(dialog){;
						dialog.doClose();
					})
				}
			}

			objRoot.prototype.onFilterRcpPkg = function(id){
				if(id != 'all'){
					this.mtxRcpPkg.filter("mcStatus",this.get("selRcpStatusFilter").getText());
				}else{
					this.mtxRcpPkg.filter();
				}
			}

			objRoot.prototype.onChooseReceiptPkgProv = function(){
				if(this && this.loadUIojb && this.loadUIojb.mtxContract){
					this.blkRcpDesc.hide();
					this.blkRcpDetail.show();
					this.selectBatchApprovalInfoId = this.mtxRcpPkg.getSelectedNodes().get(0).getAttribute("batchApprovalInfoId");
					this.loadContractData();
				}else{
					var me = this; 
					ux.megatron.Main.loadUIResourceAsync(this.getDescendantOfName('blkRcpDetail'),
							"ux.cdb.admin", 
							"ux/cdb/admin/approvePkg/ui/contracProvinceList.xml",
							me,me.onLoadProvianceModeListTabUI);
				}
			}

			objRoot.prototype.onLoadProvianceModeListTabUI = function(objEvent){
				this.blkRcpDetail = this.get("blkRcpDetail");
				this.blkRcpDesc = this.get("blkRcpDesc");

				if(this.blkRcpDesc.getDisplay() != jsx3.gui.Block.DISPLAYNONE){
					this.blkRcpDesc.setDisplay(jsx3.gui.Block.DISPLAYNONE,true);
					this.blkRcpDetail.setDisplay(jsx3.gui.Block.DISPLAYBLOCK,true);
				}
				
				if(this.blkRcpDetail.getDisplay() != jsx3.gui.Block.DISPLAYBLOCK){
					this.blkRcpDesc.setDisplay(jsx3.gui.Block.DISPLAYBLOCK,true);
					this.blkRcpDetail.setDisplay(jsx3.gui.Block.DISPLAYNONE,true);
				}

				this.loadUIojb = objEvent.obj;
				this.loadUIojb.mtxContract = this.get("mtxProvRcpPkg");
				this.loadUIojb.pagebar = this.loadUIojb.get("blkPageWheel");
				this.loadUIojb.pagebar.initialize();
				this.loadUIojb.pagebar.bindWithMatrix(this, this.loadUIojbPagination, this.loadUIojb.mtxContract);
				this.selectBatchApprovalInfoId = this.mtxRcpPkg.getSelectedNodes().get(0).getAttribute("batchApprovalInfoId");

				this.blkRcpDesc.setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
				this.blkRcpDetail.setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
				this.loadContractData();
			}

			objRoot.prototype.loadUIojbPagination = function(msg) {
                this.curPage = (msg && msg.currentPageNumber) ? msg.currentPageNumber : (this.curPage || 1);
                this.loadContractData();
            };

			objRoot.prototype.loadContractData = function(){
				var me = this;
				ux.megatron.util.Dwr.callDwr("UploadRetailStudentLoanContractFeedBackProvinceUCC",
					"getCountryBatchInfoListFromProvince",
					[this.selectBatchApprovalInfoId,this.curPage,this.pageSize],
					me,me.getCountryBatchInfoListFromProvinceCallBack,
					"UploadRetailStudentLoanContractFeedBackProvinceUCC");
			}

			objRoot.prototype.getCountryBatchInfoListFromProvinceCallBack = function(dwrObjectList){
				if(!dwrObjectList)
					jsx3.log("call getCountryBatchInfoListFromProvinceCallBack failed......");

				this.loadUIojb.totalRecordCount = dwrObjectList.content.page.count;
				this.loadUIojb.totalPages = (this.loadUIojb.totalRecordCount % this.pageSize > 0) ? (parseInt(this.loadUIojb.totalRecordCount / this.pageSize) + 1) : (this.loadUIojb.totalRecordCount / this.pageSize);
				if (this.loadUIojb.totalPages == 0) this.loadUIojb.totalPages = 1;
				this.loadUIojb.pagebar.setValue(this.curPage,this.loadUIojb.totalPages,this.pageSize,this.loadUIojb.totalRecordCount); 

				var cdfDoc = ux.megatron.util.Dwr.toShallowCdf(dwrObjectList.content.data); 
				this.loadUIojb.mtxContract.setSourceXML(cdfDoc);
				this.loadUIojb.mtxContract.repaint();
			}

			objRoot.prototype.onCheckBtnStatus = function(){
				if(this.mtxRcpPkg.getCheckedNodes().size() == 0){
					this.setBtn(["btnNew"],["btnReport","btnPrint"]);
				}
				else if(this.mtxRcpPkg.getCheckedNodes().size() == 1 ){
					this.setBtn(["btnNew","btnReport","btnPrint"]);
				}
				else{
					this.setBtn(["btnNew","btnReport"],["btnPrint"]);
				}
			}

			objRoot.prototype.setBtn = function(enableBtns,disableBtns,hideBtns){
				if(enableBtns){
					for(var i=0; i<enableBtns.length; i++) {
						this.get(enableBtns[i]).enable();
					}
				}
				if(disableBtns){
					for(var i=0; i<disableBtns.length; i++) {
						this.get(disableBtns[i]).disable();
					}
				}
				if(hideBtns){
					for(var i=0; i<hideBtns.length; i++) {
						this.get(hideBtns[i]).hide();
					}
				}
			}
		});
}

